﻿@using LdCms.EF.DbModels
@using LdCms.Common.Utility
@using LdCms.Common.Extension
@model Ld_Extend_LinkGroup
@{
    ViewData["Title"] = "ListGroup";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页<span class="c-gray en">&gt;</span>扩展管理<span class="c-gray en">&gt;</span>友情链接<span class="c-gray en">&gt;</span>分组设置
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:window.location.reload();" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>
<article class="page-container bg-eee" style="min-height:778px;">
    <div class="cl pd-20 bg-fff" style="min-height:738px;">
        <div class="tabBar cl clearfix">
            <span>基本信息</span>
        </div>
        <div class="mt-15">
            <div class="l" style="width:40%;">
                <form action="@Url.Action("SaveGroup")" method="post" class="form form-horizontal" id="form-add">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2">类别名称：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <input type="text" class="input-text" value="" placeholder="分组名称" id="fName" name="fName" />
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>外部组别：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <span class="select-box">
                                <select class="select" size="1" id="fIsExternal" name="fIsExternal">
                                    <option value="0">关闭</option>
                                    <option value="1">开启</option>
                                </select>
                            </span>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2">备注：</label>
                        <div class="formControls col-xs-8 col-sm-9">
                            <textarea id="fRemark" name="fRemark" class="textarea" placeholder="说点什么...100个字符以内" dragonfly="true"></textarea>
                            <p class="textarea-numberbar"><em class="textarea-length"></em>/100</p>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-2">审核：</label>
                        <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                            <div class="check-box">
                                <input type="checkbox" id="fState" name="fState" value="1" checked="" />
                                <label for="checkbox-1">&nbsp;</label>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                            <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                            <a href="@Url.Action("list")" class="btn btn-default radius" type="button"><i class="Hui-iconfont">&#xe66c;</i> 返回 </a>
                        </div>
                    </div>
                </form>
            </div>
            <div class="l" style="width:60%;border:0px solid #ffd800;">
                <div style="height:32px;line-height:32px;">链接分组列表：</div>
                <table class="table table-border table-bordered table-hover table-bg table-sort">
                    <thead>
                        <tr class="text-c">
                            <th width="120">名称</th>
                            <th width="">名称</th>
                            <th width="80">外部</th>
                            <th width="80">状态</th>
                            <th width="120">时间</th>
                            <th width="100">操作</th>
                        </tr>
                    </thead>
                    <tbody id="lists">
                        <tr class="text-c">
                            <td valign="top" colspan="5" class="dataTables_empty">暂无数据</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</article>
@*
    --------------
    页面底部JS脚本
    --------------
*@
@section scripts{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="~/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="~/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="~/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript" src="~/admin/static/h-ui.admin/js/H-ui.admin.common.js"></script>
    <script type="text/javascript">
        (function ($) {
            $.mainu = {
                init: function () {
                    $('.skin-minimal input').iCheck({
                        checkboxClass: 'icheckbox-blue',
                        radioClass: 'iradio-blue',
                        increaseArea: '20%'
                    });
                    $("#fRemark").Huitextarealength({
                        minlength: 4,
                        maxlength: 100
                    });
                    $.mainu.getLinkGroupList();
                },
                formSubmit: function () {
                    $("#form-add").validate({
                        rules: {
                            fName: {
                                required: true
                            }
                        },
                        onkeyup: false,
                        focusCleanup: true,
                        success: "valid",
                        submitHandler: function (form) {
                            var fState = $("input[name='fState']").is(':checked');
                            $(form).ajaxSubmit({
                                type: "POST",
                                cache: false,
                                data: { fState: fState },
                                dataType: "json",
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    if (XMLHttpRequest.status != 200) {
                                        layer.alert("POST[FAIL]", { icon: 5 });
                                    }
                                },
                                success: function (result) {
                                    var state = result.state;
                                    var message = result.message;
                                    if (state == "success") {
                                        window.location.reload();
                                    } else {
                                        layer.msg(message, { icon: 5, time: 3000 });
                                    }
                                }
                            });
                        }
                    });
                },
                getLinkGroupList: function () {
                    var url = "@Url.Action("linkgroup-list-get")";
                    $.ajaxSetup({ cache: false });
                    $.get(url, { state: true}, function (result) {
                        var state = result.state;
                        var message = result.message;
                        var sBody = "";
                        if (state == "success") {
                            var total = result.data.length;
                            console.log(total);
                            if (total == 0) {
                                sBody += '<tr class="text-c">';
                                sBody += '<td valign="top" colspan="6" class="dataTables_empty">暂无数据</td>';
                                sBody += '</tr>';
                            } else {
                                for (var i = 0; i < total; i++) {
                                    sBody += '<tr class="text-c">';
                                    sBody += '<td class="text-c">' + result.data[i].name + '</td>';
                                    sBody += '<td class="text-l">' + result.data[i].remark + '</td>';
                                    if (result.data[i].external) {
                                        sBody += '<td>是</td>';
                                    } else {
                                        sBody += '<td>否</td>';
                                    }
                                    if (result.data[i].state) {
                                        sBody += '<td>启用</td>';
                                    } else {
                                        sBody += '<td>停用</td>';
                                    }
                                    sBody += '<td>' + result.data[i].date + '</td>';
                                    sBody += '<td><a href="###" onclick="$.mainu.edit(\'' + result.data[i].id + '\')">编辑</a>  ';
                                    sBody +=' <a href = "###" onclick = "$.mainu.delete(\'' + result.data[i].id + '\')" > 删除</a></td> ';
                                    sBody += '</tr>';
                                }
                            }
                        }
                        $("#lists").html(sBody);
                    }, "json");
                },
                edit: function (id) {
                    var url = "@Url.Action("GetGroup")";
                    $.ajaxSetup({ cache: false });
                    $.get(url, { GroupID: id, }, function (result) {
                        var state = result.state;
                        var message = result.message;
                        if (state == "success") {
                            var actionUrl = "@Url.Action("SaveGroup")";
                            $("#form-add").attr({ "action": actionUrl + "?GroupID=" + id });
                            $("input[name='fName']").val(result.data.name);
                            $("select[name='fIsExternal']").val(result.data.external);
                            $("textarea[name='fRemark']").val(result.data.remark);
                        } else {
                            layer.alert(message, { icon: 5 });
                        }
                    });
                },
                delete: function (id) {
                    var url = "@Url.Action("DeleteGroup")";
                    $.ajaxSetup({ cache: false });
                    $.post(url, { GroupID: id, }, function (result) {
                        var state = result.state;
                        var message = result.message;
                        if (state == "success") {
                            $.mainu.getLinkGroupList();
                        } else {
                            layer.alert(message, { icon: 5 });
                        }
                    });
                }
            };
            $(function () {
                $.mainu.init();
                $.mainu.formSubmit();
            });

        })(jQuery);
    </script>
}

